<template>
  <div style="background-color:steelblue;width: 100%;height: 100vh;">
    <!--  修改密码-->
    <div style="width: 600px;height: 500px;margin: 0 auto;">
      <el-form :model="ruleForm"  ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="" prop="account">
          <label>用户名称:</label>
          <!--   不能输入内容-->
          <el-input v-model="ruleForm.account" disabled></el-input>
        </el-form-item>

        <el-form-item label="" prop="password">
          <label>原始密码:</label>
          <el-input v-model="ruleForm.password"></el-input>
        </el-form-item>
        <el-form-item label="" prop="newPassword">
          <label>新密码密码:</label>
          <el-input v-model="ruleForm.newPassword"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">确定</el-button>
          <el-button @click="Cannal">取消</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import code from "@/com_code/WorkerCode";

export default {
  name: "EditPassword",
  mounted() {
    console.log("password页面", this.$route.query.user);
    this.user = this.$route.query.user;
    this.ruleForm.account=this.user.account;
  },
  data() {
    return {
      user: {},
      ruleForm: {
        account: '',
        password: '',
        newPassword:''
      },
     /* rules: {
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'},
          {min: 6, max: 15, message: '长度在 6 到 15 个字符', trigger: 'click'}
        ],
        newPassword: [
          {required: true, message: '请输入密码', trigger: 'blur'},
          {min: 6, max: 15, message: '长度在 6 到 15 个字符', trigger: 'blur'}
        ],
      }*/
    };
  },
  methods: {
    submitForm() {
      if (this.ruleForm.password!==""&&this.ruleForm.newPassword!=="") {
        axios.put('api/work/UpdatePasswordEmployyee', this.ruleForm, false).then((res) => {
          // eslint-disable-next-line no-debugger
          debugger;
          console.log(res.data);
          if(res.data.code===code.updatePasswordError||res.data.code===code.updatePasswordErrorSame){
            // eslint-disable-next-line no-debugger
            debugger;
            this.$message({
              message: res.data.msg,
              type: 'error', // 设置消息类型为提示
              duration: 1000, // 设置消息显示时间为3秒，默认是2000毫秒
            });
            return
          }
          if(res.data.code==code.updatePasswordSuccess){
            console.log(res.data.data);
            this.$message({
              message: res.data.data,
              type: 'success', // 设置消息类型为提示
              duration: 2000, // 设置消息显示时间为3秒，默认是2000毫秒
            });
          }

          //传递到mutations中的方法
          this.$store.commit('RemoveUser', this.ruleForm)
          this.$router.push({name: 'login'})
        }).catch(error => {
          console.log(error);
        })
      } else {
        this.$message({
          message: '请填写完整信息!',
          type: 'error', // 设置消息类型为提示
          duration: 1000, // 设置消息显示时间为3秒，默认是2000毫秒
        });
      }
    },
    Cannal() {
      this.$router.push({name: 'home', query: {user: this.user}})
    }
  }
}
</script>
<style scoped>
.demo-ruleForm {
  padding-top: 120px;

}
</style>
